
package com.lee.fpflink; 
 
import com.lee.enumeration.FPFlinkQualifierEnum; 
import com.lee.info.CkFlowInfo; 
import com.lee.logger.Logger; 
import com.lee.tree.FPStreamGenerate; 
import com.lee.tree.PatternTree; 
import com.lee.tree.TwoTuple; 
import com.lee.utils.ConstantsUtils; 
import com.lee.utils.DCountUtils; 
import com.lee.utils.DMapUtils; 
import org.apache.flink.api.common.functions.FlatMapFunction; 
import org.apache.flink.api.common.state.MapState; 
import org.apache.flink.api.common.state.MapStateDescriptor; 
import org.apache.flink.configuration.Configuration; 
import org.apache.flink.streaming.api.functions.windowing.RichWindowFunction; 
import org.apache.flink.streaming.api.functions.windowing.WindowFunction; 
import org.apache.flink.streaming.api.windowing.windows.GlobalWindow; 
import org.apache.flink.util.Collector; 
 
import java.io.IOException; 
import java.util.ArrayList; 
import java.util.Iterator; 
import java.util.List; 
 
public class GenerateRulesWindowFunction implements FlatMapFunction<List<TwoTuple<List<String>, Long>>, List<String>> { 
 
 
    @Override
    public void flatMap(List<TwoTuple<List<String>, Long>> frequentItemsets, Collector<List<String>> collector) throws Exception {
        try {
 
            Logger.info("GenerateRulesWindowFunction -> 挖掘规则");
            long dataIndex = ConstantsUtils.DATA_BLOCK_SIZE;
            long index = DMapUtils.getItemIndex(FPFlinkQualifierEnum.DCOUNT.getCode());
            Logger.info("GenerateRulesWindowFunction -> 生成pattern tree");
            FPStreamGenerate fpStreamGenerate = FPStreamGenerate.getInstance();
            PatternTree master = fpStreamGenerate.getMaster();
            fpStreamGenerate.generate(master, frequentItemsets,index + dataIndex);
 
            DMapUtils.setItemIndex(index + dataIndex,FPFlinkQualifierEnum.DCOUNT.getCode());
            Logger.info("GenerateRulesWindowFunction -> 生成规则成功");
 
        }catch (Exception e ){
            e.printStackTrace();
            Logger.error("GenerateRulesWindowFunction -> 报错",e);
        }
    }
} 
